<?php

namespace App\Http\Middleware;
use Closure;

class DistributedJSON
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $request_json = json_decode($request->getContent(),true);
        try
        {
            // 不知道会不会检查出来有问题？？？？
            // 重定向本质上是回改变URL重新请求，我们没有注册路由，所有只能重定向到控制器。
            //redirect()->action($request_json['Controller'].'@'.$request_json['Action']);;
            redirect()->action('UserController@add');;
        }
        catch (InvalidArgumentException $e)
        {
            return response()->json(['status'=>false,'msg'=>trans('error.not_found_controller_or_action')]);
        }

        return $next($request);
    }
}
